package beans;

import net.sf.json.JSONObject;
import java.io.*;

public class SingleAlgorithmModelJson {
    private static JSONObject modelJson = null;
    private SingleAlgorithmModelJson(){}
    public static JSONObject getInstance(){
        if(modelJson==null){
            synchronized (SingleAlgorithmModelJson.class){
                if(modelJson==null){
                    try{
                        String url = Thread.currentThread().getContextClassLoader().getResource("AnnotationFiles/SingleAlgorithmModelJson.json").getPath();
                        Reader reader = new InputStreamReader(new FileInputStream(new File(url)), "utf-8");
                        int tempJsonString;
                        StringBuilder modelJsonStr = new StringBuilder();
                        while ((tempJsonString = reader.read()) != -1) {
                            modelJsonStr.append((char)tempJsonString);
                        }
                        modelJson = JSONObject.fromObject(modelJsonStr.toString());    //json转换字符串
                    }catch (IOException e){
                        e.printStackTrace();
                    }
                }
            }
        }
        return modelJson;
    }
}